﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CL.Business.BLL;
using CL.Business.Entity;
using CL.Tools.Common;

namespace CL.UnionWeb.union.modify
{
    public partial class modifypwd : BasePage
    {
        public static AccountEntity un_Entity = new AccountEntity();
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "推广联盟-修改密码";
            if (!IsPostBack)
                un_Entity = base.GetUnionInfo();
        }

        /// <summary>
        /// 修改登录密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnModifyPwd_Click(object sender, EventArgs e)
        {
            lbMsg.Text = string.Empty;
            un_Entity = base.GetUnionInfo();
            string UnionPassword = txtUnionPassword.Text.Trim();  //旧登录密码
            string NewUnionPassword = txtNewUnionPassword.Text.Trim(); //新登录密码
            string AffirmUnionPassword = txtAffirmUnionPassword.Text.Trim();  //确认新登录密码
            if(AffirmUnionPassword != NewUnionPassword)
            {
                lbMsg.Text = string.Format("新密码和确认密码不一致.");
                return;
            }

            UnionPassword = Utils.MD5(UnionPassword);
            if (un_Entity.AccountPwd != UnionPassword)
            {
                lbMsg.Text = string.Format("旧密码错误");
                return;
            }
            un_Entity.AccountPwd = UnionPassword;
            bool rec = new AccountBLL().ModifyEntity(un_Entity.AccountID, Utils.MD5(AffirmUnionPassword));
            if (rec)
            {
                new RecordBLL().InsertEntity(new Business.Entity.RecordEntity()
                {
                    AccountID = un_Entity.AccountID,
                    RecordTime = DateTime.Now,
                    RecordRemark = string.Format("密码修改成功"),
                    RecordType = 2

                });
                Session[CLKeys.SESSION_ADMIN_INFO] = null;
                SendMsgToView("密码修改成功, 请重新登录.", "/Login.aspx");
                return;
            }
            else
            {
                lbMsg.Text = string.Format("密码修改失败");
                return;
            }
        }
    }
}